import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "美食App",
      theme: ThemeData(
        /// 基础渲染颜色，一些小部件会使用这个颜色
        /// 相当于同时传入了 旧版本的 primaryColor 和 accentColor，新版本中这个两个属性已经不在使用了
        /// 这里传入的是 MaterialColor
        primarySwatch: Colors.orange,
        splashColor: Colors.transparent,

        /// 某些 widget 的主题
        buttonTheme: ButtonThemeData(height: 50, minWidth: 100),
        elevatedButtonTheme: ElevatedButtonThemeData(
            style: ElevatedButton.styleFrom(minimumSize: Size(10, 50), primary: Colors.green)),
        cardTheme: CardTheme(color: Colors.redAccent),

        /// 文字主题
        /// body 默认使用 bodyText2，bodyText1 是粗体
        textTheme:
            TextTheme(bodyText2: TextStyle(fontSize: 20), bodyText1: TextStyle(fontSize: 25)),
      ),
      darkTheme: ThemeData(
        primarySwatch: Colors.grey,
        textTheme: TextTheme(
            bodyText2: TextStyle(fontSize: 20, color: Colors.blueGrey),
            bodyText1: TextStyle(fontSize: 25)),
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Theme")),
      body: MyContent(),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
          BottomNavigationBarItem(icon: Icon(Icons.star), label: "收藏"),
        ],
      ),
      floatingActionButton: FloatingActionButton(
          onPressed: () {
            Navigator.of(context).push(PageRouteBuilder(
                pageBuilder: (context, animation, secondaryAnimation) => DetailPage()));
          },
          child: Icon(Icons.forward)),
    );
  }
}

class MyContent extends StatelessWidget {
  const MyContent({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: [
          Text("1222334"),
          Switch(value: true, onChanged: (v) {}),
          Divider(thickness: 1),
          ElevatedButton(onPressed: () {}, child: Text("11")),
          Divider(thickness: 1),
          Card(child: Text("hahahahahaha哈哈哈")),
          Card(child: Text("hahahahahaha哈哈哈", style: Theme.of(context).textTheme.bodyText1))
        ],
      ),
    );
  }
}

class DetailPage extends StatelessWidget {
  const DetailPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Theme(
      /// 局部主题 修改颜色主题
      data: Theme.of(context)
          .copyWith(colorScheme: Theme.of(context).colorScheme.copyWith(primary: Colors.yellow)),
      child: Scaffold(
        appBar: AppBar(title: Text("Detail Page")),
        body: Center(child: Text("MMMM")),
      ),
    );
  }
}
